# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: convert_ls.py
# Time: 17:07



def convert_list_to_dict(origin_list):
    """
    cover har data list to mapping
    Args:
        origin_list (list)
            [
                {"name": "v", "value": "1"},
                {"name": "w", "value": "2"},
            ]

    Returns:
        dict:
            {"v": "1", "w": "2"}
    """
    return {
        item["name"]: item.get("value")
        for item in origin_list
    }


def convert_str_to_hump(string):
    """ 将字符串转化类名
        驼峰命名：仅大写首字母
        下划线命名：以下划线为分隔符，大写每个单词首字母

    string(str): 给定字符串

    Example:
        >>> convert_str_to_hump("check_version")
        >>> convert_str_to_hump("loginByPhone")

    Returns:
        CheckVersion
        LoginByPhone

    """
    mark = "_"
    if mark in string:
        str_list = str(string).split(mark)
        first = str_list[0].lower().capitalize()
        others = str_list[1:]
        others_capital = [word.capitalize() for word in others]  # str.capitalize():将字符串的首字母转化为大写
        others_capital[0:0] = [first]
        hump_string = ''.join(others_capital)  # 将list组合成为字符串，中间无连接符。
    else:
        hump_string = string.replace(string[0], string[0].capitalize(), 1)

    return hump_string